package com.superbytecode.sample.redis.controller;

import com.superbytecode.sample.redis.entity.RedisIn;
import com.superbytecode.sample.redis.entity.User;
import com.superbytecode.sample.redis.service.RedisTemplateService;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * All rights Reserved, Designed By www.super-bytecode.com
 *
 * @ProjectName: superbytecode-beacon
 * @Package: com.superbytecode.sample.controller
 * @ClassName: RedisTemplateController
 * @Description: []
 * <p> </p>
 * @Author: [Lance Ting]
 * @Date: 2023/11/21 11:20
 * @Version: V1.0
 * @Copyright: 2023 www.super-bytecode.com Inc. All rights reserved.
 * TODO: 注意,本文件Lance Ting所作,如果转载或使用请标明具体出处!
 **/
@RestController
@RequestMapping("/com/superbytecode/sample/redis/template")
public class RedisTemplateController {
    @Resource
    private RedisTemplateService redisTemplateService;

    /**
     * 新增
     *
     * @param user 参数
     */
    @PostMapping("/add")
    public int add(@RequestBody User user) {
        Integer id = user.getId();
        return redisTemplateService.add(String.valueOf(id), user);
    }

    /**
     * 新增
     *
     * @param redisIn 参数
     */
    @PostMapping("/get")
    public Object get(@RequestBody RedisIn redisIn) {
        String key = redisIn.getKey();
        return redisTemplateService.get(key);
    }
}